[BITS 32]
global kload
kload:
    mov esp, _kernel_stack	; This points the stack to new stack area
    push eax			; Multiboot magic number
    push ebx			; Multiboot information structure
    extern main
    call main

; Align to 4 byte
ALIGN 4
mboot:
    ; Multiboot macros 
    MULTIBOOT_PAGE_ALIGN	equ 1<<0
    MULTIBOOT_MEMORY_INFO	equ 1<<1
    MULTIBOOT_AOUT_KLUDGE	equ 1<<16
    MULTIBOOT_HEADER_MAGIC	equ 0x1BADB002
    MULTIBOOT_HEADER_FLAGS	equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
    MULTIBOOT_CHECKSUM	equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
    EXTERN code, bss, end

    ; GRUB Multiboot header.
    dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM

    ; aout kludge
    dd mboot
    dd code
    dd bss
    dd end
    dd kload

; Set up our new segment registers.
; In order to set up CS, far jump is performed (far jump is a jump 
; that includes a segment and an offset)
global gdt_flush
extern gdtp

gdt_flush:
    lgdt [gdtp]
    mov ax, 0x10
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov ss, ax
    jmp 0x08:preparecs
preparecs:
    ret

; Loads the IDT.
global idt_flush
extern idtp

idt_flush:
    lidt [idtp]
    ret

SECTION .bss
    resb 8192               ; Reserve 8KB of memory
_kernel_stack:
